package com.vecspace.dayu.code.template.pojo;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.vecspace.data.model.IdEntity;
import com.vecspace.data.model.RowMapper;
import com.vecspace.dicttable.CodeItem;
import com.vecspace.dicttable.DictAll;

import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.Polymorphism;
import org.hibernate.annotations.PolymorphismType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/** 模板页面布局元素
 * @author wanghua
 */
@Entity
@Polymorphism(type = PolymorphismType.EXPLICIT)
@Table(name = "DAYU_CODE_TEMPLATE_COMPONENT")
public class TemplatePageComponent implements IdEntity, java.io.Serializable {

	private static final long serialVersionUID = -8399290067123490849L;
	public TemplatePageComponent(){
	}
	
	private Long id;
	/**逻辑ID*/
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "ID")
	public Long getId(){
		return id;
	}
	/**逻辑ID*/
	public void setId(Long value){
		this.id = value;
	}

	private Long layoutId;
	/**页面布局ID*/
	@Column(name = "LAYOUT_ID")
	public Long getLayoutId(){
		return layoutId;
	}
	/**页面布局ID*/
	public void setLayoutId(Long value){
		this.layoutId = value;
	}

	private String componentCode;
	/**页面元素编码*/
	@Column(name = "COMPONENT_CODE")
	public String getComponentCode(){
		return componentCode;
	}
	/**页面元素编码*/
	public void setComponentCode(String value){
		this.componentCode = value;
	}

	private String componentName;
	/**页面元素名称*/
	@Column(name = "COMPONENT_NAME")
	public String getComponentName(){
		return componentName;
	}
	/**页面元素名称*/
	public void setComponentName(String value){
		this.componentName = value;
	}

	private String componentType;
	public static final String ComponentTypeCode="DAYU-CODE-035";
	/**页面元素类型*/
	@Column(name = "COMPONENT_TYPE")
	public String getComponentType(){
		return componentType;
	}
	/**页面元素类型*/
	public void setComponentType(String value){
		this.componentType = value;
	}
	@Transient
	public String getComponentTypeCaption(){
		return DictAll.getItemName(ComponentTypeCode, componentType);
	}
	
	@Transient
	public List<CodeItem> getComponentTypes(){
		return DictAll.getItems(ComponentTypeCode);
	}


	private Integer ordnum;
	/**顺序号*/
	@Column(name = "ORDNUM")
	public Integer getOrdnum(){
		return ordnum;
	}
	/**顺序号*/
	public void setOrdnum(Integer value){
		this.ordnum = value;
	}

	private Date createTime;
	/**记录创建时间*/
	@JsonIgnore(true)
	@Column(name = "CREATE_TIME")
	public Date getCreateTime(){
		return createTime;
	}
	/**记录创建时间*/
	public void setCreateTime(Date value){
		this.createTime = value;
	}
	@Transient
	@JsonIgnore(true)
	public String getCreateTimeStr(){
		if(createTime == null){
			return "";
		}
		String exp = "yyyy-MM-dd";
		String timestr = new java.text.SimpleDateFormat(exp).format(createTime);
		return timestr;
	}

	private String createUser;
	/**记录创建人ID*/
	@Column(name = "CREATE_USER")
	public String getCreateUser(){
		return createUser;
	}
	/**记录创建人ID*/
	public void setCreateUser(String value){
		this.createUser = value;
	}

	
	public void parseFrom(Map<String, Object> row){
		RowMapper rowMapper = new RowMapper(row);
		this.id = rowMapper.getLong("ID");
		this.layoutId = rowMapper.getLong("LAYOUT_ID");
		this.componentCode = rowMapper.getString("COMPONENT_CODE");
		this.componentName = rowMapper.getString("COMPONENT_NAME");
		this.componentType = rowMapper.getString("COMPONENT_TYPE");
		this.ordnum = rowMapper.getInteger("ORDNUM");
		this.createTime = rowMapper.getDate("CREATE_TIME");
		this.createUser = rowMapper.getString("CREATE_USER");
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(id == null)return false;
		TemplatePageComponent other = (TemplatePageComponent)obj;
		return id.equals(other.id);
	}

	@Override
	public int hashCode() {
		if(id == null)return 0;
		return id.hashCode();
	}
}
